/**   
 * Copyright © 2016 公司名. All rights reserved.
 * 
 * @Title: DictTypeController.java 
 * @Prject: LianniuMgrSer
 * @Package: com.lianniu.mgr.baseService.dict.controller
 * @Description: TODO

 * @date: 2016年3月31日 上午9:34:15 
 * @version: V1.0   
 */
package com.lianniu.mgr.baseService.dict.controller;



import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.lianniu.mgr.base.BaseResult;
import com.lianniu.mgr.baseService.dict.model.DictTypeVo;
import com.lianniu.mgr.baseService.dict.service.IDictTypeService;
import com.lianniu.mgr.pagination.PaginationInfo;
import com.lianniu.mgr.util.StringUtil;

/** 
 * @ClassName: DictTypeController 
 * @Description: TODO

 * @date: 2016年3月31日 上午9:34:15  
 */
@Controller
@RequestMapping("/rest/dictType")
public class DictTypeRestController {
  
  private final static Logger logger = Logger.getLogger(DictTypeRestController.class);
  
  @Autowired
  private  IDictTypeService dictTypeService;
  
  /**
   * 
   * @Title: dictTypeList 
   * @Description: TODO

   * @param request
   * @param curVo
   * @param paginationInfo
   * @return
   * @date: 2016年4月2日 上午8:14:30 
   * @return: BaseResult
   */
  @RequestMapping(value="/dictTypeList",method={RequestMethod.GET,RequestMethod.POST})
  public @ResponseBody BaseResult dictTypeList(HttpServletRequest request,DictTypeVo curVo,PaginationInfo paginationInfo)
  {
       logger.info("DictTypeRestController dictTypeList begin.");
       try {
           
           logger.info("dictTypeList begin.");          
           BaseResult baseResult = dictTypeService.selectDictTypebyName(curVo, paginationInfo);
           logger.info("dictTypeList end.");
           logger.info("DictTypeRestController dictTypeList end.");
           return baseResult;
       } catch (Exception e) {
       logger.error("DictTypeRestController dictTypeList error:" + e.getMessage());
       logger.error("DictTypeRestController dictTypeList end.");
       return BaseResult.exception(e.getMessage());
     }
  }
  
  /**
   * 
   * @Title: dictTypeAdd 
   * @Description: TODO

   * @param request
   * @param curVo
   * @return
   * @date: 2016年4月2日 下午9:22:43 
   * @return: BaseResult
   */
  @RequestMapping(value = {"/dictTypeAdd"}, method = RequestMethod.POST)
  public @ResponseBody BaseResult dictTypeAdd(HttpServletRequest request,DictTypeVo curVo) {
      logger.info("DictTypeRestController dictTypeAdd begin.");      
      logger.info("DictTypeRestController dictTypeAdd:"+ JSON.toJSONString(curVo));
      try {
          logger.info("dictTypeAdd begin.");
          curVo.setId(StringUtil.getUUID());
          BaseResult baseResult = dictTypeService.insertDictType(curVo);
          logger.info("dictTypeAdd baseResult:" + JSON.toJSONString(baseResult));
          logger.info("dictTypeAdd end.");
          return baseResult;

    } catch (Exception e) {
      logger.error("dictTypeAdd error:"+e.getMessage());
      logger.info("DictTypeRestController dictTypeAdd end.");
      return BaseResult.exception(e.getMessage());
    }

  }
  
  /**
   * 
   * @Title: dictTypeEdit 
   * @Description: TODO

   * @param request
   * @param curVo
   * @return
   * @date: 2016年4月2日 下午9:22:38 
   * @return: BaseResult
   */
  @RequestMapping(value = {"/dictTypeEdit"}, method = RequestMethod.POST)
  public @ResponseBody BaseResult dictTypeEdit(HttpServletRequest request,DictTypeVo curVo) {
      logger.info("DictTypeRestController dictTypeEdit begin.");      
      logger.info("DictTypeRestController dictTypeEdit:"+ JSON.toJSONString(curVo));
      try {
          logger.info("dictTypeEdit begin.");          
          BaseResult baseResult = dictTypeService.updateDictTypeById(curVo);
          logger.info("dictTypeEdit baseResult:" + JSON.toJSONString(baseResult));
          logger.info("dictTypeEdit end.");
          return baseResult;

    } catch (Exception e) {
      logger.error("dictTypeEdit error:"+e.getMessage());
      logger.info("DictTypeRestController dictTypeEdit end.");
      return BaseResult.exception(e.getMessage());
    }
  }  
  
 /**
  * 
  * @Title: selectDictTypeById 
  * @Description: TODO

  * @param request
  * @param curVo
  * @return
  * @date: 2016年4月2日 下午9:22:32 
  * @return: BaseResult
  */
  @RequestMapping(value="/selectDictTypeById",method={RequestMethod.GET,RequestMethod.POST})
  public @ResponseBody BaseResult selectDictTypeById(HttpServletRequest request,DictTypeVo curVo) {
        logger.info("DictTypeRestController selectDictTypeById begin.");
        try {
       
          BaseResult baseResult = dictTypeService.selectDictTypeById(curVo);
          logger.info("selectDictTypeById end.");
          logger.info("DictTypeRestController selectDictTypeById end.");
          return baseResult;
        } catch (Exception e) {
          logger.error("DictTypeRestController selectDictTypeById error:" + e.getMessage());
          logger.error("DictTypeRestController selectDictTypeById end.");
          return BaseResult.exception(e.getMessage());
        }
  } 
  
  @RequestMapping(value = {"/dictTypeDel"}, method = RequestMethod.POST)
  public @ResponseBody BaseResult dictTypeDel(HttpServletRequest request) {
      logger.info("DictTypeRestController dictTypeDel begin.");
     try {          
          logger.info("dictTypeDel begin.");
          BaseResult baseResult = dictTypeService.deleteDictTypeBatch(request.getParameter("ids").split(","));
          logger.info("dictTypeDel baseResult:" + JSON.toJSONString(baseResult));
          logger.info("dictTypeDel end.");
          
          logger.info("DictTypeRestController dictTypeDel end.");
          return baseResult;

    } catch (Exception e) {
      logger.error("DictTypeRestController dictTypeDel error:" + e.getMessage());
      logger.info("DictTypeRestController dictTypeDel end.");
      return BaseResult.exception(e.getMessage());
    }

  }
  
  
  @RequestMapping(value = {"/dictTypeDelBatchLogic"}, method = RequestMethod.POST)
  public @ResponseBody BaseResult dictTypeDelBatchLogic(HttpServletRequest request) {
      logger.info("DictTypeRestController dictTypeDelBatchLogic begin.");
     try {          
          logger.info("dictTypeDelBatchLogic begin.");
          BaseResult baseResult = dictTypeService.delBatchDictTypeLogic(request.getParameter("updateUser"),request.getParameter("ids").split(","));
          logger.info("dictTypeDelBatchLogic baseResult:" + JSON.toJSONString(baseResult));
          logger.info("dictTypeDelBatchLogic end.");
          
          logger.info("DictTypeRestController dictTypeDelBatchLogic end.");
          return baseResult;

    } catch (Exception e) {
      logger.error("DictTypeRestController dictTypeDelBatchLogic error:" + e.getMessage());
      logger.info("DictTypeRestController dictTypeDelBatchLogic end.");
      return BaseResult.exception(e.getMessage());
    }

  }
  
  @RequestMapping(value = {"/checkTypeName"}, method = RequestMethod.POST)
  public @ResponseBody Boolean checkTypeName(HttpServletRequest request) {
      Boolean flag=true;
      String typeName=  request.getParameter("typeName");
      logger.info("DictTypeRestController checkTypeName begin.");
     try {          
          logger.info("checkTypeName begin.");
          if("".equalsIgnoreCase(typeName)||typeName==null)
          {return flag;}
          flag = dictTypeService.checkTypeName(typeName);         
          logger.info("checkTypeName end.");
          
          logger.info("DictTypeRestController checkTypeName end.");
          return flag;
    } catch (Exception e) {
      logger.error("DictTypeRestController checkTypeName error:" + e.getMessage());
      logger.info("DictTypeRestController checkTypeName end.");
      return flag;
    }

  }
  
  
  @RequestMapping(value = {"/checkTypeNameEdit"}, method = RequestMethod.POST)
  public @ResponseBody Boolean checkTypeNameEdit(HttpServletRequest request) {
      Boolean flag=true;
      String typeName=  request.getParameter("typeName");
      String typeId=request.getParameter("id");
      logger.info("DictTypeRestController checkTypeNameEdit begin.");
     try {          
          logger.info("checkTypeNameEdit begin.");
          DictTypeVo vo=new DictTypeVo();
          vo.setId(typeId);
          BaseResult baseResult =dictTypeService.selectDictTypeById(vo);
          DictTypeVo curVo=(DictTypeVo) baseResult.getData();
          if(curVo.getId().equals(typeId)&&curVo.getTypeName().equals(typeName))
          {return flag;}
          if("".equalsIgnoreCase(typeName)||typeName==null)
          {return flag;}
          flag = dictTypeService.checkTypeName(typeName);         
          logger.info("checkTypeNameEdit end.");
          
          logger.info("DictTypeRestController checkTypeNameEdit end.");
          return flag;
    } catch (Exception e) {
      logger.error("DictTypeRestController checkTypeNameEdit error:" + e.getMessage());
      logger.info("DictTypeRestController checkTypeNameEdit end.");
      return flag;
    }

  }
  
  
  
}
